<%--
  Created by IntelliJ IDEA.
  User: gaosubo
  Date: 2020/9/12
  Time: 18:42
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>结题等级</title>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=10,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <link rel="stylesheet" type="text/css" href="/lib/layui/layui/css/layui.css"/>
    <script type="text/javascript" src="/js/news/jquery-1.9.1.js"></script>
    <script src="/js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../js/jquery/jquery.cookie.js"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.ui.widget.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.iframe-transport.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.fileupload.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" src="/js/common/fileupload.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/layui.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/layui.all.js"></script>
</head>
<style>
    .btn {
        text-align: right;
    }
    .item img {
        height: 40px;
    }

    .item{
        line-height: 40px;
        margin-top: 8px;
        margin: 8px;
        margin-left: 20px;
    }
    .layui-icon-ok{
        margin-top: 6px;
    }
</style>
<body>
<div>
    <div class="item">
        <div class="item">
            <img src="../img/yeji.png" alt="" style="margin: 0 5px 0 20px;">
            <span style="font-size: 22px;display: inline-block;vertical-align: middle;">结题定级</span>
        </div>
    </div>
    <hr class="layui-bg-blue">
    <div>
        <div class="btn">
            <div style="margin-left: 10px;float: left" class="layui-form">
                <input type="radio" checked name="status"  lay-filter="status" value="1" title="未提交">
                <input type="radio" name="status" value="2"  lay-filter="status" title="已提交">
            </div>
            <div>
                <button type="button" class="layui-btn immp layui-btn-sm "  style="margin-right: 15px; display: none" >
                    总分百分百筛选
                </button>
                <button type="button" class="layui-btn layui-btn-sm" id="takeDeg"  style="margin-right: 15px;" >
                    设置等级
                </button>
                <button type="button" class="layui-btn layui-btn-sm" id="commit"  style="margin-right: 15px;" >
                    提交
                </button>
                <button type="button" class="layui-btn immp layui-btn-sm " id="del" style="margin-right: 15px" >
                    <i class="layui-icon">&#xe601;</i>
                    导出
                </button>
            </div>
        </div>
    </div>
    <div>
        <table class="layui-hide" id="test" lay-filter="test"></table>
    </div>
</div>

</body>
</html>
<script type="text/html" id="barDemo">
    <div class="layui-btn-container">
        <a class="layui-btn layui-btn-xs" lay-event="addCheckData">设置等级</a>
    </div>
</script>
<script>
    var tableInt2;

    layui.use(['table', 'layer', 'form','laydate'], function () {
        var table = layui.table
            , layer = layui.layer
            , form = layui.form
            , laydate = layui.laydate

        $(document).ready(function(){
            form.render();
        });

        // 初始化结题申请数据
        $.ajax({
            url: '/conclusion_apply/initializationConclusionData'
            , type: 'post'
            , data: {
                trType: "23"
                , trStatus: "2"
                , type: "30"
                , status: "1"
                , flag: false
            }
            , dataType: 'json'
            , async: false
            , success: function (res) {}
        });

        var tableInt = table.render({
            elem: '#test'
            , url: '/conclusion_apply/getConclusionApply'
            , where: {
                trType: "30"
                , trStatus: "1"
            }
            , defaultToolbar: ['']
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {field: 'topicName', title: '项目名称'}
                , {field: 'planName', title: '申报计划名称'}
                , {field: 'trOther2', title: '学段评分'}
                , {field: 'reviewFraction', title: '专家平均分'}
                , {field: 'zongfen', title: '总分', align: 'center'}
                , {field: 'dengji', title: '等级'}
                , {field: 'names', title: '项目成员'}
                , {field: 'headUserName', title: '负责人'}
                , {field: 'type', title: '操作', toolbar: '#barDemo'}
            ]],
            page:true,
        });

        function noToolTbale(type) {
            tableInt2 = table.render({
                elem: '#test'
                , url: '/conclusion_apply/getConclusionApply'
                , where: {
                    trType: "30"
                    , trStatus: "2"
                }
                , defaultToolbar: ['']
                , cols: [[
                    {type: 'checkbox', fixed: 'left'}
                    , {field: 'topicName', title: '项目名称'}
                    , {field: 'planName', title: '申报计划名称'}
                    , {field: 'trOther2', title: '学段评分'}
                    , {field: 'reviewFraction', title: '专家平均分'}
                    , {field: 'zongfen', title: '总分', align: 'center'}
                    , {field: 'dengji', title: '等级'}
                    , {field: 'names', title: '项目成员'}
                    , {field: 'headUserName', title: '负责人'}
                ]],
                page:true,
            });
        }

        //监听顶部单选按钮
        form.on('radio(status)', function(data){
            switch (data.value) {
                case "1":
                    $("#pfBox").css("display","");
                    $("#commit").css("display","");
                    $("#takeDeg").css("display","");
                    tableInt.reload({
                        where: {
                            trType: "30"
                            , trStatus: "1"
                        }
                    });
                    break;
                case "2":
                    noToolTbale(2);
                    $("#pfBox").css("display","none");
                    $("#commit").css("display","none");
                    $("#takeDeg").css("display","none");
                    break;
            }
        });
        $("#takeDeg").click(function(){
            var data = table.checkStatus('test').data;
            var topicIds = "";
            for (var i = 0; i < data.length; i++) {
                topicIds += data[i].topicId + ",";
            }
            if(data.length>0){
                layer.open({
                    type: 1,
                    title: '设置等级',
                    btn: ['确定', '取消'],
                    shade: 0.5,
                    area: ['35%', '50%'],
                    content:' <div class="layui-form-item" style="margin-top: 10px">' +
                    '    <div class="layui-inline">' +
                    '      <label class="layui-form-label">优秀：</label>' +
                    '      <div class="layui-input-inline">' +
                    '        <input id="trOther" placeholder="最大值" style="display:inline-block;width: 88px;" type="text" name="trOther"  autocomplete="off" class="layui-input">到<input id="trOther2" placeholder="最小值" style="display:inline-block;width: 88px;"type="text" name="trOther2"  autocomplete="off" class="layui-input">' +
                    '      </div>' +
                    '    </div>' +
                    '    <div class="layui-inline">' +
                    '      <label class="layui-form-label">良好：</label>' +
                    '      <div class="layui-input-inline">' +
                    '        <input id="trOther3" placeholder="最大值" style="display:inline-block;width: 88px;" type="text" name="trOther3"  autocomplete="off" class="layui-input">到<input id="trOther4" placeholder="最小值" style="display:inline-block;width: 88px;" type="text" name="trOther4"  autocomplete="off" class="layui-input">' +
                    '      </div>' +
                    '    </div>' +
                    '    <div class="layui-inline">' +
                    '      <label class="layui-form-label">合格：</label>' +
                    '      <div class="layui-input-inline">' +
                    '        <input id="trOther5" placeholder="最大值" style="display:inline-block;width: 88px;" type="text" name="trOther5"  autocomplete="off" class="layui-input">到<input id="trOther6" placeholder="最小值" style="display:inline-block;width: 88px;" type="text" name="trOther6"  autocomplete="off" class="layui-input">' +
                    '      </div>' +
                    '    </div>' +
                    '  </div>',
                    success: function () {
                        form.render();
                    },
                    yes:function (index) {
                        if($("#trOther").val()!=""&&$("#trOther2").val()!=""&&$("#trOther3").val()!=""&&$("#trOther4").val()!=""&&$("#trOther5").val()!=""&&$("#trOther6").val()!=""){
                            if(Number($("#trOther").val())>Number($("#trOther2").val())&&Number($("#trOther3").val())>Number($("#trOther4").val())&&Number($("#trOther5").val())>Number($("#trOther6").val())){
                                layer.close(index);
                                var data = {
                                    topicIds:topicIds,
                                    trOther:$("#trOther").val(),
                                    trOther2:$("#trOther2").val(),
                                    trOther3:$("#trOther3").val(),
                                    trOther4:$("#trOther4").val(),
                                    trOther5:$("#trOther5").val(),
                                    trOther6:$("#trOther6").val()

                                }
                                $.ajax({
                                    url: '/cnclusion/setGrade',
                                    dataType: 'json',
                                    type: 'post',
                                    data:data,
                                    success: function (res) {
                                        if(res.code == 0){
                                            layer.msg(res.msg);
                                            tableInt.reload();
                                        }else{
                                            layer.msg(res.msg);
                                        }
                                    }
                                });
                            }else{
                                layer.msg('第一个输入框的值应大于第二个');
                                return false;
                            }
                        }else{
                            layer.msg('请填写完整后进行操作');
                            return false;
                        }
                    }
                });
            }else{
                layer.msg("请选中数据进行设置等级");
                return false;
            }

        })
        //通过操作
        $("#commit").click(function(){
            var data = table.checkStatus('test').data;
            if (data.length > 0) {
                var trIds = "";
                for (var i = 0; i < data.length; i++) {
                    trIds += data[i].trId + ",";
                }
                layer.confirm('是否确认提交', {
                    btn: ['确认', '取消'],
                    icon: 7,
                    title: "系统提示"
                }, function () {
                    $.ajax({
                        url: '/conclusion_apply/submitData'
                        , type: 'post'
                        , data: {
                            ids: trIds
                            , newTrType: 25
                            , newTrStatus: 0
                            , oldTrType: 30
                            , oldTrStatus: 2
                            , oldStatusChange: 2
                        }
                        , dataType: 'json'
                        , async: false
                        , success: function (res) {
                            var msg = "";
                            if (res.code == 0) {
                                layer.msg("提交成功", {time: 1500, icon: 1});
                            } else {
                                layer.msg("提交失败", {time: 1500, icon: 2});
                            }
                            tableInt.reload();
                        }
                    });
                }, function () {
                    parent.layer.closeAll();
                });
            }else{
                layer.msg("请选中数据进行提交");
                return false;
            }
        })
        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            console.log(data);
            var topicIds = data.topicId + ",";
            if(obj.event === 'addCheckData') {
                layer.open({
                    type: 1,
                    title: '设置等级',
                    btn: ['确定', '取消'],
                    shade: 0.5,
                    area: ['35%', '50%'],
                    content:' <div class="layui-form-item" style="margin-top: 10px">' +
                    '    <div class="layui-inline">' +
                    '      <label class="layui-form-label">优秀：</label>' +
                    '      <div class="layui-input-inline">' +
                    '        <input id="trOther" placeholder="最大值" style="display:inline-block;width: 88px;" type="text" name="trOther"  autocomplete="off" class="layui-input">到<input id="trOther2" placeholder="最小值" style="display:inline-block;width: 88px;"type="text" name="trOther2"  autocomplete="off" class="layui-input">' +
                    '      </div>' +
                    '    </div>' +
                    '    <div class="layui-inline">' +
                    '      <label class="layui-form-label">良好：</label>' +
                    '      <div class="layui-input-inline">' +
                    '        <input id="trOther3" placeholder="最大值" style="display:inline-block;width: 88px;" type="text" name="trOther3"  autocomplete="off" class="layui-input">到<input id="trOther4" placeholder="最小值" style="display:inline-block;width: 88px;" type="text" name="trOther4"  autocomplete="off" class="layui-input">' +
                    '      </div>' +
                    '    </div>' +
                    '    <div class="layui-inline">' +
                    '      <label class="layui-form-label">合格：</label>' +
                    '      <div class="layui-input-inline">' +
                    '        <input id="trOther5" placeholder="最大值" style="display:inline-block;width: 88px;" type="text" name="trOther5"  autocomplete="off" class="layui-input">到<input id="trOther6" placeholder="最小值" style="display:inline-block;width: 88px;" type="text" name="trOther6"  autocomplete="off" class="layui-input">' +
                    '      </div>' +
                    '    </div>' +
                    '  </div>',
                    success: function () {
                        $.ajax({
                            url: '/cnclusion/getGradle',
                            dataType: 'json',
                            type: 'post',
                            data:{
                                topicId:data.topicId
                            },
                            success: function (res) {
                                $("#trOther").val(res.object.trOther);
                                $("#trOther2").val(res.object.trOther2);
                                $("#trOther3").val(res.object.trOther3);
                                $("#trOther4").val(res.object.trOther4);
                                $("#trOther5").val(res.object.trOther5);
                                $("#trOther6").val(res.object.trOther6);
                            }
                        });
                        form.render();
                    },
                    yes:function (index) {
                        if($("#trOther").val()!=""&&$("#trOther2").val()!=""&&$("#trOther3").val()!=""&&$("#trOther4").val()!=""&&$("#trOther5").val()!=""&&$("#trOther6").val()!=""){
                            if(Number($("#trOther").val())>Number($("#trOther2").val())&&Number($("#trOther3").val())>Number($("#trOther4").val())&&Number($("#trOther5").val())>Number($("#trOther6").val())){
                                layer.close(index);
                                var data = {
                                    topicIds:topicIds,
                                    trOther:$("#trOther").val(),
                                    trOther2:$("#trOther2").val(),
                                    trOther3:$("#trOther3").val(),
                                    trOther4:$("#trOther4").val(),
                                    trOther5:$("#trOther5").val(),
                                    trOther6:$("#trOther6").val()

                                }
                                $.ajax({
                                    url: '/cnclusion/setGrade',
                                    dataType: 'json',
                                    type: 'post',
                                    data:data,
                                    success: function (res) {
                                        if(res.code == 0){
                                            layer.msg(res.msg);
                                            tableInt.reload();
                                        }else{
                                            layer.msg(res.msg);
                                        }
                                    }
                                });
                            }else{
                                layer.msg('请填写完整后进行操作');
                                return false;
                            }
                        }else{
                            layer.msg('请填写完整后进行操作');
                            return false;
                        }
                    }
                });
            }
        });
    });
</script>
